var aas: string[] = ["a", "b", "c"]
console.log(aas[0])

var arrs: string[] = new Array<string>()
arrs.push("aa")
arrs.push("bb")

console.log(arrs[0])

var arrn:number[] = [12,13] 
var[x,y] = arrn // 将数组的两个元素赋值给变量 x 和 y
console.log(x) 
console.log(y)

var j:any; 
var nums:number[] = [1001,1002,1003,1004] 
 
for(j in nums) { 
    console.log(nums[j]) 
}
//检查元素值是否大于1002
var isBig = nums.every((element, index, array)=>{
    return element > 1002
})

console.log(isBig)
var f = function(element: number, index: number, array: any) : boolean{
    return element > 1002
}
//过滤数组
var vf = nums.filter(f)
for(j in vf) { 
    console.log(vf[j]) 
}

var a1:string[] = ["a1","b1"]
var a2:string[] = ["a2","b2"]
//合并
var a1a2: string[] = a1.concat(a2)
var aaa: any
for(aaa in a1a2) {
    console.log(a1a2[aaa])
}
// console.log(a1a2)
console.log("foreach")
//foreach
a1a2.forEach(function(v){
    console.log(v)
})
//lambda
a1a2.forEach(v=>{
    console.log(v)
})

//查找元素位置
console.log( a1a2.indexOf("b1"))
//查找从后向前
console.log( a1a2.lastIndexOf("b2"))

//拼接字符串
console.log( a1a2.join(","))

//map 遍历处理数据 每个元素加mmm
var m = a1a2.map((element: string, index: number, array: any)=>{
    return "mmm" + element  
})
console.log(m)

console.log("---------del")
//删除最后的元素
var del = a1a2.pop()
console.log(del)
//删除第一个的元素
var dels = a1a2.shift()
console.log(dels)


console.log("---------add")
//开始位置添加元素 添加的后的长度
var unsh = a1a2.unshift("d1","e1")
console.log(unsh)

//添加并返回添加的后的长度
var add = a1a2.push("c1")
console.log(add)

//逐2个遍历数据
var total = nums.reduce((a,b)=>{
    return a+b
})
console.log(total)
//逐2个遍历数据 从右向左
var totalr = nums.reduceRight((a,b)=>{
    return a+b
})
console.log(totalr)
console.log("---------------")
//反转
var re = nums.reverse()
for(j in re){console.log(re[j])}
//根据下标截取新数组
var newA1a2 = a1a2.slice(2,4)
for(j in newA1a2){console.log(newA1a2[j])}
console.log("--------------------")

//检查元素是否有包含条件的值
var someNums = nums.some((element: number, index: number, array: any)=>{
    return element > 1002
})
console.log(someNums)

//排序
var sre = re.sort()
for(j in sre){console.log(sre[j])}

console.log("------splice--------------")
//指定位置添加或删除  开始位置  删除个数 返回删除的元素
var revmoed = nums.splice(0,1) 
for(j in revmoed){console.log(revmoed[j])}

//删除后添加  返回删除的元素
var revm = nums.splice(0,1,2001,3001)
for(j in revm){console.log(revm[j])}
for(j in nums){console.log(nums[j])}

console.log(a1a2.toString())

